package com.fengyunhe.common;

import java.util.List;

/**
 * 功能：后台管理节点
 * 作者： yangyan
 * 时间： 2014/8/15 .
 */
public class ManagementNode {

    /**
     * 模块ID，在同级中不能重复
     */
    private String id;

    /**
     * 模块的名称
     */
    private String name;

    /**
     * 注释
     */
    private String comment;

    /**
     * 子模块
     */
    private List<ManagementNode> children;
    /**
     * 该模块可控制权限
     */
    private List<ModulePermission> permissions;

    /**
     * 是否隐藏节点，并将子节点提升层级
     */
    private boolean virtual;


    /**
     * 模块
     *
     * @param id   模块ID，在同级中不能重复
     * @param name 名称
     */
    public ManagementNode(String id, String name) {
        this.id = id;
        this.name = name;
    }

    /**
     * 是否有子模块
     *
     * @return
     */
    public boolean hasSubModule() {
        if (children != null && !children.isEmpty()) {
            return true;
        }
        return false;
    }

    protected String getId() {
        return id;
    }


    public String getName() {
        return name;
    }


    public void setChildren(List<ManagementNode> children) {
        this.children = children;
    }

    public List<ManagementNode> getChildren() {
        return children;
    }

    public List<ModulePermission> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<ModulePermission> permissions) {
        this.permissions = permissions;
    }


    protected ManagementNode parent;

    /**
     * 返回模块的唯一id
     *
     * @return
     */
    public final String getFullId() {
        if (parent == null) {
            return this.getId();
        } else {
            return parent.getFullId() + "." + this.getId();
        }
    }


    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public boolean isVirtual() {
        return virtual;
    }

    public void setVirtual(boolean virtual) {
        this.virtual = virtual;
    }
}
